<!DOCTYPE html>
<html lang="zh-Hans-CN">
    <head>
        <title>SSE服务器消息推送</title>
        <meta charset="utf-8" />
        <meta name="keywords" content="" />
        <meta name="description" content="" />
        <meta name="author" content="chen" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge, chrome=1" />
        <!--
            <link rel="stylesheet" type="css/text" media="screen and ( min-width: 1200px )" href="">
        -->
        <link rel="stylesheet" type="text/css" media="screen" href="" />
        <script defer="defer" src=""></script>
        <style>
            /*@import url("css/name.css") screen and ( min-width: 1200px );*/
        </style>
    </head>

    <body>
        <div id="box"></div>
        <script>
            //  允许前端获取来自后端的信息推送
            const source = new EventSource("./sse.php");
            source.onmessage = function(e) {
                console.log(JSON.parse(e.data));
                box.innerText += e.data + "\n";
            };
        </script>
    </body>
</html>
